package code.coolbaby.basal.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import code.coolbaby.basal.dao.RoleDao;
import code.coolbaby.basal.entity.Role;
import code.coolbaby.core.orm.hibernate.EntityManager;
import code.coolbaby.core.utils.ServiceException;
import code.coolbaby.core.utils.SpringSecurityUtils;

/**
 * 角色管理类.
 * 
 * @author Kanine
 */
@Service
public class RoleManager extends EntityManager<Role, Long> {

	@Autowired
	protected RoleDao roleDao;

	protected RoleDao getEntityDao() {
		return roleDao;
	}
	
	/**
	 * 重载delte函数,演示异常处理及用户行为日志.
	 */
	@Override
	public void delete(Long id) {
		if (id == 1) {
			logger.warn("操作员{}尝试删除超级管理员用户角色", SpringSecurityUtils.getCurrentUserName());
			throw new ServiceException("不能删除超级管理员角色");
		}

		roleDao.delete(id);
	}
}
